DAILY_ANALYSIS_CONFIG = {
    'real_time_report': False,
    'interval_type_list': ['day'],
    'day_to_calc': [0, 1, 2, 3, 4, 5, 6, 13, 29, 59],
    'target_event_id': ['bet_order', 'recharge', 'withdraw', 'active', 'register', 'bind'],
    'on_day_event_id': ['bet_order', 'withdraw', 'register', 'bind'],
    'values': [
        {
            "value_id": "register_user",
            "target_value": "_user_id",
            "value_name": "注册账号",
            "filter": [
                {'term': {'_event_id': 'register'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "当日新创建用户数量"
        },
        {
            "value_id": "bind_register_user",
            "target_value": "_user_id",
            "value_name": "注册绑定账号",
            "filter": [
                {'term': {'_event_id': 'bind'}},
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "当日新创建并绑定手机号的用户数量"
        },
        {
            "value_id": "bind_user",
            "target_value": "_user_id",
            "value_name": "绑定账号",
            "filter": [
                {'term': {'_event_id': 'bind'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "当日进行手机号绑定的用户数量"
        },
        {
            "value_id": "today_login",
            "target_value": "_user_id",
            "value_name": "登录账号",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "当日登录大厅的用户数量"
        },
        {
            "value_id": "today_ios_login",
            "target_value": "_user_id",
            "value_name": "IOS登录用户",
            "filter": [
                {'term': {'_event_id': 'active'}},
                {'term': {'_device_type': 2}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "当日iOS设备登录的用户数"
        },
        {
            "value_id": "today_android_login",
            "target_value": "_user_id",
            "value_name": "android登录用户",
            "filter": [
                {'term': {'_event_id': 'active'}},
                {'term': {'_device_type': 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "当日Android设备登录的用户数"
        },
        {
            "value_id": "recharge_user_count",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "new_user_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "新用户充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "veteran_user_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "老用户充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "not_filter": [
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "online_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "在线充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'_is_new_user': [0, 1]}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "new_user_online_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "新用户在线充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "veteran_user_online_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "老用户在线充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality",
            "value_type": "long"
        },

        {
            "value_id": "agency_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "代理充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'_is_new_user': [0, 1]}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality",
            "value_type": "long",
        },
        {
            "value_id": "new_user_agency_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "新用户代理充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality",
            "value_type": "long",
        },
        {
            "value_id": "veteran_user_agency_recharge_user_count",
            "target_value": "_user_id",
            "value_name": "老用户代理充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "register_recharge_rate",
            "value_name": "注充率",
            "value_expr": "recharge_user_count / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "充值账号 / 活跃账号"
        },
        {
            "value_id": "register_bind_rate",
            "value_name": "注绑率",
            "value_expr": "bind_user / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_bind_rate",
            "value_name": "绑充率",
            "value_expr": "recharge_user_count / bind_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "hide_result": True,
            "description": "充值帐号 / 绑定帐号"
        },
        {
            "value_id": "recharge_amount",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "new_user_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "新用户充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "veteran_user_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "老用户充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}}
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "online_recharge",
            "target_value": "recharge_price",
            "value_name": "在线充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "new_user_online_recharge",
            "target_value": "recharge_price",
            "value_name": "新用户在线充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True
        },
        {
            "value_id": "veteran_user_online_recharge",
            "target_value": "recharge_price",
            "value_name": "老用户在线充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "agency_recharge",
            "target_value": "recharge_price",
            "value_name": "代理充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "new_user_agency_recharge",
            "target_value": "recharge_price",
            "value_name": "新用户代理充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "veteran_user_agency_recharge",
            "target_value": "recharge_price",
            "value_name": "老用户代理充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 0}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "recharge_count",
            "target_value": "_user_id",
            "value_name": "充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "online_recharge_count",
            "target_value": "_user_id",
            "value_name": "在线充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}}
            ],
            "not_filter": [
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "agency_recharge_count",
            "target_value": "_user_id",
            "value_name": "代理充值次数",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'terms': {'recharge_sub_type.keyword': ['agency_pay', 'mf_pay']}},
            ],
            "operation": "value_count",
            "value_type": "long"
        },
        {
            "value_id": "average_recharge",
            "value_name": "人均充值",
            "value_expr": "recharge_amount /recharge_user_count",
            "adjust_amount": True,
            "description": "充值金额 / 充值账号"
        },
        {
            "value_id": "active_user",
            "target_value": "_user_id",
            "value_name": "登录账号",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "real_active_user",
            "target_value": "_user_id",
            "value_name": "活跃账号",
            "filter": [
                {"terms": {"_event_id": ["withdraw", "recharge", "bet_order", "active", "register"]}},
            ],
            "not_filter": [
                {'term': {"bet_order_user_type": 1}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "recharge_rate",
            "value_name": "付费率",
            "value_expr": "recharge_user_count / real_active_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "充值账号 / 活跃账号"
        },
        {
            "value_id": "profit",
            "target_value": ["recharge_price", '-', "withdraw_real_price"],
            "value_name": "财务营收",
            "filter": [
                {'terms': {'_event_id': ['recharge', 'withdraw']}},
            ],
            "value_type": "float",
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "average_donate",
            "value_name": "人均贡献",
            "value_expr": "profit / real_active_user",
            "adjust_amount": True,
            "description": "玩法营收 / 活跃账号"
        },
        {
            "value_id": "withdraw_amount",
            "target_value": "withdraw_real_price",
            "value_name": "提现金额",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
        },
        {
            "value_id": "withdraw_user",
            "target_value": "_user_id",
            "value_name": "提现账号",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "operation": "cardinality",
            "value_type": "long"
        },
        {
            "value_id": "real_active_user",
            "value_name": "活跃账号",
            "value_expr": "real_active_user",
            "value_type": "long",
            "description": "当日具任一活跃行为的用户数量，\n包含登录、注册、充值、提现、投注等行为"
        },
        {
            "value_id": "profit_recharge_rate",
            "value_name": "利润率",
            "value_expr": "profit / recharge_amount",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "财务营收 / 充值金额"
        },
        {
            "value_id": "profit",
            "value_name": "财务营收",
            "value_expr": "profit",
            "adjust_amount": True,
            "description": "充值金额 - 提现金额"
        },
        {
            "value_id": "yesterday_stay_2_user",
            "target_value": "_user_id",
            "value_name": "昨日次留",
            "filter": [
                {'term': {'_event_id': 'active'}}
            ],
            "time_range": {
                "_registered_at": [-2, -2],
                "_event_time": [-1, -1]
            },
            "operation": "cardinality",
            "value_type": "long",
            "description": "(当日)前天的次日留存"
        },
        {
            "value_id": "stay_2_user",
            "target_value": "_user_id",
            "value_name": "次日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_3_user",
            "target_value": "_user_id",
            "value_name": "3日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 2}}
            ],
            "time_range": {
                "_event_time": [2, 2]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_4_user",
            "target_value": "_user_id",
            "value_name": "4日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 3}}
            ],
            "time_range": {
                "_event_time": [3, 3]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_5_user",
            "target_value": "_user_id",
            "value_name": "5日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 4}}
            ],
            "time_range": {
                "_event_time": [4, 4]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_6_user",
            "target_value": "_user_id",
            "value_name": "6日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 5}}
            ],
            "time_range": {
                "_event_time": [5, 5]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_7_user",
            "target_value": "_user_id",
            "value_name": "7日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 6}}
            ],
            "time_range": {
                "_event_time": [6, 6]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_8_user",
            "target_value": "_user_id",
            "value_name": "8日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 7}}
            ],
            "time_range": {
                "_event_time": [7, 7]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_9_user",
            "target_value": "_user_id",
            "value_name": "9日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 8}}
            ],
            "time_range": {
                "_event_time": [8, 8]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_10_user",
            "target_value": "_user_id",
            "value_name": "10日留存",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 9}}
            ],
            "time_range": {
                "_event_time": [9, 9]
            },
            "operation": "cardinality",
            "value_type": "long",
            "hide_result": True
        },
        {
            "value_id": "stay_user_rate_2",
            "value_name": "次日留存",
            "value_expr": "stay_2_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第二天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_3",
            "value_name": "3日留存",
            "value_expr": "stay_3_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第是三天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_4",
            "value_name": "4日留存",
            "value_expr": "stay_4_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第四天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_5",
            "value_name": "5日留存",
            "value_expr": "stay_5_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第五天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_6",
            "value_name": "6日留存",
            "value_expr": "stay_6_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第六天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_7",
            "value_name": "7日留存",
            "value_expr": "stay_7_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第七天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_8",
            "value_name": "8日留存",
            "value_expr": "stay_8_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第八天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_9",
            "value_name": "9日留存",
            "value_expr": "stay_9_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第九天登录的账号／第一天新增账号"
        },
        {
            "value_id": "stay_user_rate_10",
            "value_name": "10日留存",
            "value_expr": "stay_10_user/register_user",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "新增后第十天登录的账号／第一天新增账号"
        },
        {
            "value_id": "seven_day_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "7日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 6]
            },
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "seven_days_ltv",
            "value_name": "7日LTV",
            "value_expr": "seven_day_agg_recharge / register_user",
            "adjust_amount": True,
            "description": "当日用户七日累计付费金额／首日新增账号"
        },
        {
            "value_id": "fourteen_day_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "14日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 13]
            },
            "hide_result": True,
            "adjust_amount": True,
            "description": "当日用户十四日累计付费金额／首日新增账号"
        },
        {
            "value_id": "fourteen_days_ltv",
            "value_name": "14日LTV",
            "value_expr": "fourteen_day_agg_recharge / register_user",
            "adjust_amount": True,
        },
        {
            "value_id": "month_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "30日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 29]
            },
            "hide_result": True,
            "adjust_amount": True,
            "description": "当日用户三十日累计付费金额／首日新增账号"
        },
        {
            "value_id": "month_ltv",
            "value_name": "30日LTV",
            "value_expr": "month_agg_recharge / register_user",
            "adjust_amount": True,
        },
        {
            "value_id": "two_months_agg_recharge",
            "target_value": "recharge_price",
            "value_name": "60日累计付费金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
            ],
            "time_range": {
                "_event_time": [0, 59]
            },
            "hide_result": True,
            "adjust_amount": True,
            "description": "当日用户六十日累计付费金额／首日新增账号"
        },
        {
            "value_id": "two_months_ltv",
            "value_name": "60日LTV",
            "value_expr": "two_months_agg_recharge / register_user",
            "adjust_amount": True,
        },
        {
            "value_id": "arpu",
            "value_name": "ARPU",
            "value_expr": "recharge_amount / real_active_user",
            "adjust_amount": True,
            "description": "所有活跃账号人均付费金额，付费金额 / 活跃账号"
        },
        {
            "value_id": "arppu",
            "value_name": "ARPPU",
            "value_expr": "recharge_amount / recharge_user_count",
            "adjust_amount": True,
            "description": "所有付费账号人均付费金额，付费金额 / 付费账号"
        },
        {
            "value_id": "total_tax_amount",
            "target_value": "bet_order_tax_amount",
            "value_name": "玩法税收",
            "filter": [{"term": {'bet_order_user_type': 0}}],
            "operation": "sum",
            "adjust_amount": True,
            "value_type": "float",
            "description": "游戏中赢家所产生的固定比例手续费"
        },
        {
            "value_id": "average_tax",
            "value_name": "人均税收",
            "value_expr": "total_tax_amount / real_active_user",
            "adjust_amount": True,
            "description": "总税收 / 活跃账号"
        },
        {
            "value_id": "bet_profit_amount",
            "target_value": ["bet_order_bet_amount", "-", "bet_order_award_amount"],
            "value_name": "玩法营收",
            "filter": [{"term": {'bet_order_user_type': 0}}],
            "operation": "sum",
            "hide_result": True,
            "adjust_amount": True,
        },
        {
            "value_id": "system_profit",
            "value_name": "系统输赢",
            "value_expr": "bet_profit_amount - total_tax_amount",
            "adjust_amount": True,
            "description": "玩法营收 - 玩法税收"
        }
    ]
}
